import { OptionItem } from '@/components/ui/combobox.js';

import { CustomService } from './custom-service.js';

// 定义支持的远程选项类型
export type RemoteOptionType = 'modelList' | 'mcpList' | 'otherOptionType2';

/**
 * 根据remoteOptions类型获取对应的选项数据
 * @param type - 远程选项类型
 * @param signal - 用于取消请求的AbortSignal
 * @returns 选项数据数组Promise
 */
export const fetchRemoteOptions = async (
  type: RemoteOptionType,
  signal: AbortSignal
): Promise<OptionItem[]> => {
  const customService = new CustomService();
  console.log('type', type);
  switch (type) {
    case 'modelList':
      const models = await customService.getModelList(signal);
      return models.map((model) => ({
        label: model.Name,
        value: model.ID,
      }));
    case 'mcpList':
      const mcps = await customService.getMcpList(signal);
      return mcps.map((mcp) => ({
        label: mcp.Name,
        value: mcp.ID,
      }));

    // 可以在这里添加其他remoteOptions类型的处理
    // case 'otherOptionType1':
    //   const data = await customService.getOtherData(signal);
    //   return data.map(item => ({ label: item.name, value: item.id }));

    default:
      throw new Error(`Unsupported remote option type: ${type}`);
  }
};
